function selecterInit() {
    var $colum = $(".smswitch");
    $colum.bootstrapSwitch({
        size: "small",
        onSwitchChange: function (event, state) {
            var target = event.target;
            var cur_eid = target.dataset.deviceId;
            var vOnOff="";
            bootbox.confirm(state ? "确认要执行开启操作吗?" : "确认要执行关闭操作吗?", function (result) {
                if (result) {
                    vOnOff = state?"startup":"shutdown";

                    if(cur_eid && cur_eid != ""){
                        onAjaxSwitch(ctx+"/biz/basic/sendcmd?device="+cur_eid+"&cmd="+vOnOff);
                    }else{
                        Messenger().post("操作失败!");
                    }
                } else {
                    $(target).trigger("previousState.bootstrapSwitch", true);
                }
            });
        }
    });
}

function doStartup(eid,msg){
    bootbox.confirm(msg == undefined?"确认要执行开启操作吗?":msg, function (result) {
        if (result) {
            onAjaxSwitch(ctx+"/biz/basic/sendcmd?device="+eid+"&cmd=startup");
        }
    });
}

function doShutdown(eid,msg){
    bootbox.confirm(msg == undefined?"确认要执行关闭操作吗?":msg, function (result) {
        if (result) {
            onAjaxSwitch(ctx+"/biz/basic/sendcmd?device="+eid+"&cmd=shutdown");
            if(eid == "69"){
                onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=71&cmd=toBackup");
                onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=72&cmd=toBackup");
                onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=70&cmd=startup");
                setTimeout(function () {
                    onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=70&cmd=freq&value="+$("section[data-id='69'] input[date_pram_id='freq']").val());
                },1000);
                setTimeout(function () {
                    transAndSentPower("70",$("section[data-id='69'] input[date_pram_id='pow']").val());
                },2000);
                // console.info(ctx+"/biz/basic/sendcmd?device=70&cmd=freq&value=714");
                // onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=70&cmd=freq&value=714");
            }
            // if(eid == "70"){
            //     onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=71&cmd=toMaster");
            //     onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=69&cmd=startup");
            //     // setTimeout(function () {
            //     //     onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=70&cmd=freq&value=714");
            //     // },800);
            //
            // }
        }
    });
}

function doSwitchMaster(msg) {
    bootbox.confirm(msg == undefined?"确认要执行倒主操作吗?":msg, function (result) {
        if (result) {
            onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=70&cmd=shutdown");
            onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=72&cmd=toMaster");
            onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=71&cmd=toMaster");
            onAjaxSwitch(ctx+"/biz/basic/sendcmd?device=69&cmd=startup");
        }
    });

}

function onAjaxSwitch(url, state) {
    $.ajax({
        type: "POST",
        dataType: "json",
        url: url,
        data: "state=" + state,
        success: function (msg) {
            if (msg == "1") {
                Messenger().post("操作指令已发送!");
            } else {
                $colum.trigger("previousState.bootstrapSwitch", true);
                Messenger().post("操作失败!");
            }
        }
    })
}